/**
 * TradeGood.java
 */
// $codepro.audit.disable numericLiterals
package edu.gatech.startrader.trade;

import java.util.Random;

import edu.gatech.startrader.universe.Planet;
import edu.gatech.startrader.universe.Planet.SpecialResources;


/**
 * TradeGood Enumerated Type
 * ten different goods you can trade
 * The first four (water, furs, food and ore) are natural resources, 
 * which are cheapest in low-tech systems. 
 * The other six (games, firearms, medicine, machines, 
 * narcotics and robots) are industrial goods 
 * and are cheapest in high-tech systems
 * @author Team Bamf (Team 30)
 */
public enum TradeGood 
{
	/**
	 * Water TradeGood
	 */
	WATER(0, 
			0, 
			2, 
			30, 
			3, 
			4, 
			0, 
			Planet.SpecialResources.LOTS_OF_WATER, 
			Planet.SpecialResources.DESERT, 
			30, 
			50, 
			false,
			"Hot gasses heat up the planet and large quantities of water dry up. Water prices have dramatically increased.",
			"Ice from comets melt into water, flooding the planet. Water prices have dramatically decreased."),
	
	/**
	 * Fur TradeGood
	 */
	FUR(0, 
			0, 
			0, 
			250, 
			10, 
			10, 
			0, 
			Planet.SpecialResources.RICH_FAUNA, 
			Planet.SpecialResources.LIFELESS, 
			230, 
			280, 
			false,
			"A massive meteor kills of numerous populations of animals. Fur prices have dramatically increased.",
			"Animals on the planet are in heat. Populations skyrocket. Fur prices have dramatically decreased."),
	
	/**
	 * Food TradeGood
	 */
	FOOD(1, 
			0, 
			1, 
			100, 
			5, 
			5, 
			0, 
			Planet.SpecialResources.RICH_SOIL, 
			Planet.SpecialResources.POOR_SOIL, 
			90, 
			160, 
			false,
			"A mysterious virus kills the food supply on the planet. Food prices have dramatically increased.",
			"An alien catalyst promotes life on the planet. Food prices have dramatically decreased."),
	
	/**
	 * Ore TradeGood
	 */
	ORE(2, 
			2, 
			3, 
			350, 
			20, 
			10, 
			0, 
			Planet.SpecialResources.MINERAL_RICH, 
			Planet.SpecialResources.MINERAL_POOR, 
			350, 
			420, 
			false,
			"The planet has exhausted its mineral resources. Ore prices have dramatically increased.",
			"A planet wide gold rush occurs! Ore prices have dramatically decreased!"),
	
	/**
	 * Games TradeGood
	 */
	GAMES(3, 
			1, 
			6, 
			250, 
			-10, 
			5, 
			0, 
			Planet.SpecialResources.ARTISTIC, 
			null, 
			160, 
			270, 
			false,
			"Zombie communitsts take over the planet's goverment! Boredom ensues. Game prices have dramatically increased.",
			"A wave of inspiration surges through the planet's population. Games galore! Game prices have dramatically decreased"),
	
	/**
	 * Firearms TradeGood
	 */
	FIREARMS(3,
			1, 
			5,
			1250,
			-75,
			100,
			0,
			Planet.SpecialResources.WAR_LIKE,
			null,
			600,
			1100,
			true,
			"A World War breaks out! Firearm prices have dramatically increased.",
			"World Peace for all! Firearm prices have dramatically decreased."),
	
	/**
	 * Medicine TradeGood
	 */
	MEDICINE(4,
			1,
			6,
			650,
			-20,
			10,
			0,
			Planet.SpecialResources.LOTS_OF_HERBS,
			null,
			400,
			700,
			false,
			"A mysterious sickness siezes the planet's population. Everyone is sick. Medicine prices have dramatically increased.",
			"Humanitarian doctors work tirelessly for free, no strings attached. Medicine prices have dramatically decreased."),
	
	/**
	 * Machines TradeGood
	 */
	MACHINES(4,
			3,
			5,
			900,
			-30,
			5,
			0,
			null,
			null,
			600,
			800,
			false,
			"An industrial revolution ensues! Machines are needed everywhere! Machine prices have dramatically increased",
			"Manual labor costs have plummeted. Machine prices have dramatically decreased."),
	
	/**
	 * Narcotics TradeGood
	 */
	NARCOTICS(5,
			0,
			5,
			3500,
			-125,
			150,
			0,
			Planet.SpecialResources.WEIRD_MUSHROOMS,
			null,
			2000,
			3000,
			true,
			"The goverment has imposed excessive bans and taxes on all drugs. Narcotics prices have dramatically increased.",
			"'Say No to Drugs' campaigns stop consumer need for illicit drugs. Narcotics prices have dramatically decreased"),
	
	/**
	 * Robots TradeGood
	 */
	ROBOTS(6,
			4,
			7,
			5000,
			-150,
			100,
			0,
			null,
			null,
			3500,
			5000,
			false,
			"It's a robot revolution! Looking for recruits, the price of Robots has dramatically increased",
			"People started reading Asimov's books. Robots are shunned. The price of Robots has dramatically decreased");
	
	/**
	 * The minimum TechLevel a Planet needs to produce the TradeGood
	 */
	private final int minimumProductionTechLevel;
	
	/**
	 * The minimum TechLevel a Planet needs to buy the TradeGood
	 */
	private final int minimumUsageTechLevel;
	
	/**
	 * The TechLevel that produces the most of the TradeGood
	 */
	private final int optimalTechLevel;
	
	/**
	 * The Base Price used to determine the price of the TradeGood
	 */
	private final int basePrice;
	
	/**
	 * The increment as the TechLevel of the Planet changes
	 */
	private final int techLevelPriceIncrease;
	
	/**
	 * The maximum change in price due to chance
	 */
	private final int priceVariance;
	
	/**
	 * The conditions on a Planet that make the buy 
	 * price of the TradeGood low and the sell price high
	 */
	private final Planet.SpecialResources cheapCondition;
	
	/**
	 * The conditions on a Planet that make the buy 
	 * price of the TradeGood high and the sell price low
	 */
	private final Planet.SpecialResources expensiveCondition;
	
	/**
	 * The minimum price of a Trader for the TradeGood
	 */
	private final int minTraderPrice;
	
	/**
	 * The maximum price of a Trader for the TradeGood
	 */
	private final int maxTraderPrice;
	
	/**
	 * In the random event of increase, display this message
	 */
	private final String increaseEventMessage;
	
	/**
	 * In the random event of decrease, display this message
	 */
	private final String decreaseEventMessage;
	
	/**
	 * Whether a good is illegal to trade or not
	 */
	private final boolean illegal;
	
	/**
	 * Private TradeGood Constructor
	 * Creates a TradeGood and sets the default price and default amount 
	 * @param minProduceLvl Minimum Tech Level to Produce this resource 
	 * (You can't buy on planets below this level)
	 * @param minResourceLvl Minimum Tech Level to Use this resource 
	 * (You can't sell on planets below this level)
	 * @param mostProduceLvl Tech Level which produces the most of this item
	 * @param price base price of the TradeGood which you can expect 
	 * when no special situations take place 
	 * and systems don't have any special resources
	 * @param priceIncrease Price increase per tech level
	 * @param maxPercentageVariance variance is the maximum percentage that the price can
	 *  vary above or below the base
	 * @param priceIncEvent Radical price increase event, when this even happens 
	 * on a planet, the price may increase astronomically
	 * @param cheapCond When this condition is present, the price of this 
	 * resource is unusually low
	 * @param priceyCond  When this condition is present, the resource is expensive
	 * @param minTrPrice Min price offered in space trade with random trader (not on a planet)
	 * @param maxTrPrice Max price offered in space trade with random trader (not on a planet)
	 * @param notLegal whether the good is illegal or not
	 * @param incEvent what is displayed in the case of a increase event
	 * @param decEvent what is displayed in the case of a decrease event
	 */
	private TradeGood(int minProduceLvl,  // $codepro.audit.disable largeNumberOfParameters
			int minResourceLvl, 
			int mostProduceLvl,
			int price, 
			int priceIncrease, 
			int maxPercentageVariance,
			int priceIncEvent, 
			Planet.SpecialResources cheapCond, 
			Planet.SpecialResources priceyCond, 
			int minTrPrice, 
			int maxTrPrice,
			boolean notLegal,
			String incEvent,
			String decEvent) {
		minimumProductionTechLevel = minProduceLvl;
		minimumUsageTechLevel = minResourceLvl;
		optimalTechLevel = mostProduceLvl;
		basePrice = price;
		techLevelPriceIncrease = priceIncrease;
		priceVariance = maxPercentageVariance;
		cheapCondition = cheapCond;
		expensiveCondition = priceyCond;
		minTraderPrice = minTrPrice;
		maxTraderPrice = maxTrPrice;
		illegal = notLegal;
		increaseEventMessage = incEvent;
		decreaseEventMessage = decEvent;
	}

	/**
	 * calculatePrice method for Planets
	 * calculate buy and sell prices for the planet's resources
	 * @param planet that the resources are on
	 * @return buy price and sell price for the planet's resource
	 */
	public int calculatePrice(Planet planet) {
		final Random rand = new Random();
		int price;
		final int planetTechLevel = planet.getTechLevel().getValue();
		if(planetTechLevel < this.minimumUsageTechLevel) {
			price = 0;
		} else {
			final int variance = -priceVariance + rand.nextInt(2 * priceVariance + 1);
			price = basePrice + 
					techLevelPriceIncrease * 
					(planetTechLevel - minimumProductionTechLevel)
					+ variance;
		}
		final Planet.SpecialResources sr = planet.getSpecialResources();
		if(cheapCondition != null && sr == cheapCondition) { 
			price *= 0.5;
		}
		if(expensiveCondition != null && sr == expensiveCondition) {
			price *= 2.0;
		}
		return price;
	}
	
	/**
	 * Calculate prices for Trader Encounters
	 * @return the price
	 */
	public int calculatePrice() {
		return minTraderPrice + new Random().nextInt(maxTraderPrice - minTraderPrice);
	}
	
	/**
	 * determineAmount method
	 * This method determines the amount of resources on a planet
	 * @param planet that has resources
	 * @return number of each resource on a planet
	 */
	public int determineAmount(Planet planet) {
		final Random rand = new Random();
		int resourceAmt = rand.nextInt(40) + 10;
		final int planetTechLevel = planet.getTechLevel().getValue();
		final Planet.SpecialResources sr = planet.getSpecialResources();
		if(planetTechLevel < minimumProductionTechLevel) {
			resourceAmt = 0;
		}
		if(cheapCondition != null && sr == cheapCondition){
			resourceAmt *= 5;
		}
		if(expensiveCondition != null && sr == expensiveCondition){
			resourceAmt /= 5;
		}
		return resourceAmt; 
	}
	
	/**
	 * Gets the increase message
	 * @return the increase message
	 */
	public String getIncreaseMessage() {
		return increaseEventMessage;
	}
	
	/**
	 * Gets the decrease message
	 * @return the decrease message
	 */
	public String getDecreaseMessage() {
		return decreaseEventMessage;
	}
}
